package com.zhouyong.netty.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * @author 99Savage
 * @date 2023/3/13 14:24
 */
public class Utils {

    private static Properties properties;

    /**
     * 静态代码块：加载配置
     */
    static {
        try {
            InputStream resource = Utils.class.getResourceAsStream("/application.properties");
            properties = new Properties();
            properties.load(resource);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 读取配置获取接口的实现类，并通过反射实例化对象
     */
    public static Object getServiceInstance(Class<?> serviceClass) throws Exception {
        return Class.forName(properties.getProperty(serviceClass.getName())).newInstance();
    }

}
